package org.eae.eldf.webapp.controller.main;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import org.eae.eldf.webapp.base.AbstractController;
import org.eae.eldf.framework.spring.SpringSecurityUtils;
import org.eae.eldf.service.sys.SysOperatorService;



@Controller
public class HomeController extends AbstractController {
	
	@Autowired
	private SysOperatorService operatorService;
	
	
	@RequestMapping(value = "/")
	public String homePage(ModelMap model,HttpServletRequest request) {
		return home(model,request);
	}
	@RequestMapping(value = "/home.htm")
	public String home(ModelMap model,
			HttpServletRequest request) {
		Object currentUsername = request.getSession().getAttribute("current_username");
		Object userMenu = request.getSession().getAttribute("userMenu");
		if(null == currentUsername){
			request.getSession().setAttribute("current_username", SpringSecurityUtils.getCurrentUserName());
		}
		if(userMenu==null){
			request.getSession().setAttribute("userMenu", operatorService.getMenusByUser());
		}
		return "/home";
	}
	
//	//返回json示例
//	 	@RequestMapping("/testJson")   
//	    public @ResponseBody SysOperator getJson(@RequestParam(required = false) String account){  
//	 		SysOperator op = operatorService.findByUser(account);
//	         
//	        return op;  
//	    }
	 	
	 	
//		public void setOperatorService(SysOperatorService operatorService) {
//			this.operatorService = operatorService;
//		}
//		public void setMenu_service(SysMenuService menu_service) {
//			this.menu_service = menu_service;
//		}  

		
	 	
}
